package com.ruoyi.web.controller.good;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.good.domain.GoodStock;
import com.ruoyi.good.service.IGoodStockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物资出入库Controller
 *
 * @author rockvan
 * @date 2023-04-09
 */
@Api("物资出入库管理")
@RestController
@RequestMapping("/good/goodstock")
public class GoodStockController extends BaseController
{
    @Autowired
    private IGoodStockService goodStockService;

    /**
     * 查询物资出入库列表
     */
    @ApiOperation("获取物资出入库列表")
    @PreAuthorize("@ss.hasPermi('good:goodstock:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodStock goodStock)
    {
        startPage();
        List<GoodStock> list = goodStockService.selectGoodStockList(goodStock);
        return getDataTable(list);
    }

    /**
     * 导出物资出入库列表
     */
    @ApiOperation("导出物资出入库列表")
    @PreAuthorize("@ss.hasPermi('good:goodstock:export')")
    @Log(title = "物资出入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodStock goodStock)
    {
        List<GoodStock> list = goodStockService.selectGoodStockList(goodStock);
        ExcelUtil<GoodStock> util = new ExcelUtil<GoodStock>(GoodStock.class);
        util.exportExcel(response, list, "物资出入库数据");
    }

    /**
     * 获取物资出入库详细信息
     */
    @ApiOperation("获取物资出入库详细信息")
    @ApiImplicitParam(name = "id", value = "物资编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('good:goodstock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(goodStockService.selectGoodStockById(id));
    }

    /**
     * 新增物资出入库
     */
    @ApiOperation("新增物资出入库信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accept", value = "物质去向", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "peopleName", value = "联系人", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "operateType", value = "操作类型", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "goodName", value = "物资名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "goodNum", value = "物资数量", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "goodSize", value = "物资单位", dataType = "String", dataTypeClass = String.class),
    })
    @PreAuthorize("@ss.hasPermi('good:goodstock:add')")
    @Log(title = "物资出入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodStock goodStock)
    {
        return toAjax(goodStockService.insertGoodStock(goodStock));
    }

    /**
     * 修改物资出入库
     */
    @ApiOperation("修改物资出入库信息")
    @PreAuthorize("@ss.hasPermi('good:goodstock:edit')")
    @Log(title = "物资出入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodStock goodStock)
    {
        return toAjax(goodStockService.updateGoodStock(goodStock));
    }

    /**
     * 删除物资出入库
     */
    @ApiOperation("删除物资出入库信息")
    @ApiImplicitParam(name = "ids", value = "物资编号", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermi('good:goodstock:remove')")
    @Log(title = "物资出入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(goodStockService.deleteGoodStockByIds(ids));
    }
}
